import axios from "axios";
import utils from "@/utils/index";
import { Toast } from 'vant';

const service = axios.create({
  // 超时时间
  timeout: 300000,
});
// 请求拦截
service.interceptors.request.use(
  (config) => {
    if (config.url.includes('login') || config.url.includes('register')) {

    } else {
      const token = localStorage.getItem("token")
      config.headers["Authorization"] = token
    }
    config.baseURL = process.env.VUE_APP_BASE_API;
    return config;
  },
  (err) => {
  }
);

// 响应拦截
service.interceptors.response.use(
  (response) => {
    if (response.data.code != '200') {
      Toast.fail(response.data.message);
    }
    return response.data;
  },
  (err) => {
    // 请求报错
  }
);

export default service;
